import request from '@/utils/request'

export function getUserCenter(header?: any) {
  return request.get({ url: '/admin/appuser/info', header })
}

// 注销账号
export function userDel() {
  return request.delete({ url: '/admin/appuser/del' })
}

// 个人编辑
export function userEdit(data: any) {
  return request.put({ url: '/admin/appuser/edit', data })
}

// 绑定手机
export function userBindMobile(data: any, header?: any) {
  return request.post({ url: '/admin/user/bindMobile', data, header }, { isAuth: true })
}

export function userChangePwd(data: any) {
  return userEdit(data)
}

// 绑定小程序
export function mnpAuthBind(data: any) {
  return request.post({ url: '/admin/user/bindMnp', data })
}

// 绑定公众号
export function oaAuthBind(data: any) {
  return request.post({ url: '/admin/user/bindOa', data })
}

//更新微信小程序头像昵称
export function updateUser(data: Record<string, any>, header: any) {
  return request.post({ url: '/admin/user/updateUser', data, header })
}

// 我的地址
export function addressPage(data: Record<string, any>): PmsPage<IAddress> {
  return request.get({ url: '/admin/m/my/address/page', data })
}

// 支付
export function pay(data: Record<string, any>) {
  return request.post({ url: '/admin/biz/pay/order', data })
}

// 查询支付结果
export function payOrder(payFlowId: string) {
  return request.get({ url: `/admin/biz/pay/order/${payFlowId}` })
}

// 捕捉支付
export function payCapture(payFlowId: string) {
  return request.post({ url: `/admin/biz/pay/${payFlowId}/capture` })
}

// 我的订单
export function orderPage(data: Record<string, any>): PmsPage<IOrder> {
  return request.get({
    url: '/admin/m/my/order/page',
    data,
    header: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 修改订单
export const changeOrderApi = (data: any) => {
  return request.put({
    url: `/admin/m/order/address`,
    data
  })
}

// 取消订单
export function orderCancel(orderId: string) {
  return request.put({
    url: `/admin/m/order/cancel/${orderId}`,
    header: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 新增-修改评价
export function prodEvaluateUpdate(data: Record<string, any>) {
  return request.put({
    url: '/admin/m/prodEvaluate/update',
    data
  })
}

// 评价订单（批量评价产品）
export function prodEvaluateAddBatch(data: Record<string, any>) {
  return request.post({
    url: '/admin/m/prodEvaluate/addBatch',
    data
  })
}

// 申请退款
export function orderRefund(data: Record<string, any>) {
  return request.post({
    url: '/admin/m/order/refund',
    data
  })
}

// 取消退款
export function refundCancel(data: Record<string, any>) {
  return request.put({
    url: '/admin/m/order/refund/cancel',
    data
  })
}

// 确认收货
export function orderReceipt(orderId: string) {
  return request.put({
    url: `/admin/m/order/receipt/${orderId}`
  })
}

// 订单产品添加到购物车
export function orderCart(orderId: string) {
  return request.post({
    url: `/admin/m/order/cart/${orderId}`
  })
}

// 地址列表
export function getAddressList(data: object) {
  return request.get({
    url: `/admin/m/my/address/list`,
    data
  })
}

// 添加地址
export function add_Address(data: object) {
  return request.post({
    url: `/admin/m/my/address`,
    data
  })
}

// 修改地址
export function update_Address(data: object) {
  return request.put({
    url: `/admin/m/my/address`,
    data
  })
}

// 删除地址
export function del_Address(id: string) {
  return request.delete({
    url: `/admin/m/my/address/${id}`
  })
}

// 获取地址信息
export function get_my_adress(id: string) {
  return request.get({
    url: `/admin/m/my/address/${id}`
  })
}

// 设置默认地址
export function default_address(id: string) {
  return request.put({
    url: `/admin/m/my/address/${id}/default`
  })
}


// 获取消息通知配置
export function getMsgNotifyConfig() {
  return request.get({
    url: '/admin/m/my/msg-notify-config'
  })
}

// 修改消息通知配置
export function editMsgNotifyConfig(data: any) {
  return request.put({
    url: '/admin/m/my/msg-notify-config',
    data
  })
}
